package day2.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Utils {
    static Connection con;
    static PreparedStatement st;
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("注册失败！");
        }
        String url = "jdbc:mysql://localhost:3306/a";
        String user = "root";
        String pass = "123";
        try {
            con = DriverManager.getConnection(url, user, pass);
        } catch (SQLException e) {
            System.out.println("获取数据库连接失败！");
        }
    }
//    public static Connection getConnection(){
//        try {
//            Class.forName("com.mysql.jdbc.Driver");
//        } catch (ClassNotFoundException e) {
//            System.out.println("注册失败！");
//        }
//        String url = "jdbc:mysql://localhost:3306/a";
//        String user = "root";
//        String pass = "123";
//        try {
//            con = DriverManager.getConnection(url, user, pass);
//        } catch (SQLException e) {
//            System.out.println("获取数据库连接失败！");
//        }
//        return con;
//    }

    public static PreparedStatement getSt(String sql){
        try {
            st = con.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return st;
    }
}
